package com.distribute.core.core.el;

import org.springframework.context.expression.MethodBasedEvaluationContext;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.lang.Nullable;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

public class ResultEvaluationContext extends MethodBasedEvaluationContext {

	private final Set<String> unavailableVariables = new HashSet<>(1);

	ResultEvaluationContext(Object rootObject, Method method, Object[] arguments,
							ParameterNameDiscoverer parameterNameDiscoverer) {

		super(rootObject, method, arguments, parameterNameDiscoverer);
	}

	public void addUnavailableVariable(String name) {
		this.unavailableVariables.add(name);
	}


	@Override
	@Nullable
	public Object lookupVariable(String name) {
		if (this.unavailableVariables.contains(name)) {
			// 	throw new VariableNotAvailableException(name);
			return null;
		}
		return super.lookupVariable(name);
	}

}
